/**
 * Created by c66 on 2017/7/20.
 */
/**
 * 解析时间戳获取正确时间
 * @param time 时间戳
 * @returns {string} 解析后的时间
 */
// function getLocalTime(time) {
//     var datetime = new Date();
//     datetime.setTime(time);
//     var year = datetime.getFullYear();
//     var month = datetime.getMonth() + 1;
//     var date = datetime.getDate();
//     var hour = datetime.getHours();
//     var minute = datetime.getMinutes();
//     var second = datetime.getSeconds();
//     // var mseconds = datetime.getMilliseconds();
//     return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
// }
/**
 * 时间格式取年月日
 * @param time
 * @returns {*}
 */
function getYearMonthDate(time) {
    if(time!=null) {
        var YMD = time.split(" ")[0];  // 年月日
        var HMS = time.split(" ")[1];  // 时分秒
        return YMD;
    }
    return null;
}
layui.config({
    base: '../../static/js/layuiModulesEX/'
});
layui.use(['paging','form','laytpl'], function() {
    var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
        layer = layui.layer, //获取当前窗口的layer对象
        form = layui.form(),
        laytpl = layui.laytpl;

    paging.init({
        openWait: true,
        url:'/internlog/findByCondition',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
            composerid:publisherid
        },
        contentType : "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: 'paged', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
            //alert('渲染成功');
        },
        fail: function(msg) { //获取数据失败的回调
            //alert('获取数据失败')
        },
        complate: function() {

            $('#content').children('tr').each(function() {
                //获取每行记录的id值
                var $that = $(this).children('td:last-child');
                var id = $that.children('a[data-opt=details]').data('id');
                //绑定所有编辑按钮
                // console.log(id);
                //绑定所有预览按钮
                $that.children('a[data-opt=details]').on('click', function() {
                    axios.get('/internlog/findById/'+id)
                        .then(function (response) {
                            console.log(response.data.data);
                            vm.internLog = response.data.data.internLog;
                            vm.orgInfo=response.data.data.orgInfo;
                            console.log(vm.orgInfo);
                            var divshow = $("#hello");
                            divshow.text("");// 清空数据
                            console.log(vm.internLog.content);
                            divshow.html(vm.internLog.content);
                            var divshow1 = $("#hello1");
                            divshow1.text("");
                            divshow1.html(vm.internLog.advisorappraise);
                        })
                        .catch(function (response) {
                            console.log(response);
                        });
                    vm.detailsshow = true;
                    vm.show=false;
                    vm.editshow=false;
                });
                $that.children('a[data-opt=edit]').on('click',function () {

                    axios.get('/internlog/findById/'+id)
                        .then(function (response) {
                            vm.internLog = response.data.data.internLog;
                            vm.orgInfoFullName=response.data.data.orgInfoFullName;
                            location.href='/student/editDiary?test=' + vm.internLog.content+'&test1='+id;
                            // $("#hello").attr("value","vm.internLog.content");
                            // var divshow = $("#hello");
                            // divshow.text("");// 清空数据
                            // console.log(vm.internLog.content);
                            // divshow.html(vm.internLog.content); // 添加Html内容，不能用Text 或 Val
                        })
                        .catch(function (response) {
                            console.log(response);
                        });
                    vm.detailsshow = false;
                    vm.show=false;
                    vm.editshow=true;
                });
            });
        }
    });
    var vm = new Vue({
        el:'#Vue',
        data:{
            show:true,
            editshow:false,
            detailsshow:false,
            internLog:{
                publisherid:publisherid,
            },
            orgInfo:{},
            studentId:""
        },
        methods:{
            /**
             * 添加按钮
             */
            add:function () {
                // axios.get('/student/findDetail/'+publisherid)
                //     .then(function (response) {
                //         console.log(response);
                //     })
                //     .catch(function (msg) {
                //         console.log(msg);
                //     })
                axios.all([axios.get('/student/findDetail/'+publisherid),axios.post('/internInfo/findByCondition',{sno:vm.studentId, orgattr:2, state:5})])
                    .then(function (response) {
                        console.log(response);
                        var student_res = response[0];
                        var internInfo_res = response[1];
                        console.log(student_res);
                        console.log(internInfo_res);
                        if(student_res.data.data.studentInfo == null){
                            layer.msg('请先完善个人信息');
                        }
                        else{
                            if(internInfo_res.data.data == null){
                                layer.msg('你暂无实习信息！');
                            }
                            else{
                                window.location='/student/addDiary';
                            }
                        }
                    })
                    .catch(function (msg) {
                        console.log(msg);
                    })
            },
            /**
             * 暂时保存
             */
            temporarilySaved:function () {

                vm.saveOrUpdate();
            },
            /**
             * 查询按钮
             */
            search:function () {
                paging.get({
                    title:$('#searchVal').val()
                });
            },
            reload:function () {
                vm.show=true;
                vm.detailsshow = false;
                vm.editshow=false;
                paging.get();
            }
        }
    });
});